package com.day17.File;

import java.io.File;

public class FileDemo04 {
    public static void main(String[] args) {
        File f = new File("d:\\a.txt");
        System.out.println(f.isDirectory());
        System.out.println(f.isFile());
        System.out.println(f.exists());
        System.out.println(f.getAbsoluteFile());
        System.out.println(f.getPath());
        System.out.println(f.getName());
        System.out.println("---------");

        File f2 = new File("d:\\a.txt");
        if (f2.isDirectory()) {
            String[] atrArray = f2.list();
            if (atrArray != null) {
                for (String s : atrArray) {
                    System.out.println(s);
                }
            } else {
                System.out.println("Directory is empty or cannot be accessed.");
            }
        } else {
            System.out.println("f2 is not a directory.");
        }
        System.out.println("---------");

        if (f2.isDirectory()) {
            File[] fileArray = f2.listFiles();
            if (fileArray != null) {
                for (File file : fileArray) {
                    if (file.isFile()) {
                        System.out.println(file.getName());
                    }
                }
            } else {
                System.out.println("Directory is empty or cannot be accessed.");
            }
        } else {
            System.out.println("f2 is not a directory.");
        }
    }
}

